package org.koyi.fragments;

import java.util.ArrayList;
import java.util.List;

import org.koyi.birrapp.DetallesActivity;
import org.koyi.entities.Bares;
import org.koyi.listadapters.BuscarAdapterListItem;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.View;
import android.widget.ListView;

public class BuscarListFragment extends ListFragment {

	private static List<Bares> listaBares = null;
	
	public static BuscarListFragment initialize(List<Bares> listaBares)
	{
		BuscarListFragment buscarListfragment = new BuscarListFragment();
		initializeList(listaBares);
		
		return buscarListfragment;
	}
	
	@Override
    public void onActivityCreated(Bundle savedInstanceState) 
	{
        super.onActivityCreated(savedInstanceState);
        
        if(listaBares != null)
        {
        	setListAdapter(new BuscarAdapterListItem(getActivity(), listaBares));
        }
        else
        {
        	listaBares = new ArrayList<Bares>();
        	setListAdapter(new BuscarAdapterListItem(getActivity(), listaBares));
        }
    }
	
	@Override
	public void onListItemClick(ListView l, View v, int position, long id) 
	{
		super.onListItemClick(l, v, position, id);
		
		Intent intent = new Intent(this.getActivity(), DetallesActivity.class);
		intent.putExtra("selectedBar", (Bares)l.getItemAtPosition(position));
		startActivity(intent);		
	}

	private static void initializeList (List<Bares> listaBares)
	{
		
		BuscarListFragment.listaBares = listaBares;
	}
}

